﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace stockUploader.Core
{
    [Serializable()]
    public class Stock
    {
        [XmlElement("Name")]
        public string Name { get; set; }
        [XmlElement("Ftp")]
        public string Ftp { get; set; }
        [XmlElement("Folder", IsNullable = true)]
        public string Folder { get; set; }
        [XmlElement("Login")]
        public string Login { get; set; }
        [XmlElement("Password")]
        public string Password { get; set; }
        //[XmlElement("PassiveMode", IsNullable=true, Type=typeof(Boolean))]
        //public bool? PassiveMode { get; set; }
    }


    [Serializable()]
    [XmlRoot("Settings")]
    public class Settings
    {
        [XmlArray("Stocks")]
        [XmlArrayItem(typeof(Stock))]
        public Stock[] Stocks { get; set; }

        public static Settings Load()
        {
            return Load(AppDomain.CurrentDomain.BaseDirectory + "settings.xml");
        }
        public static Settings Load(string xml)
        {
            var s = new XmlSerializer(typeof(Settings));
            using(TextReader r = new StreamReader(xml))
            {
                return (Settings)s.Deserialize(r);
            }
        }
    }
}
